package server

import (
	"ce-cloud-service/internal/config"
	"ce-cloud-service/internal/define"
	"ce-cloud-service/internal/services/gate/hall/http"
	"ce-cloud-service/internal/services/gate/hall/service"
	"ce-cloud/pkg/log"
	"ce-cloud/pkg/service/p_go_micro"
	"fmt"
	"go-micro.dev/v4"
)

var httpServer *http.ApiServer

var svc micro.Service

func Start() {
	var err error

	svc = p_go_micro.NewService(define.NewService(p_go_micro.MicroServiceInfo{
		Name:       define.ServiceNameGateHall,
		Version:    define.Version,
		ServerType: p_go_micro.ConstServerTypeNotUseDB,
	}))
	//微服务客户端初始化
	service.Init(svc.Client())
	//启动http
	go func() {
		log.Infof("config.GlobalConf.Gate.Hall[http]:%+v", fmt.Sprintf("%s:%d", config.GlobalConfig.Hall.Host, config.GlobalConfig.Hall.Port))
		httpServer, err = http.Start(config.GlobalConfig.Hall.Host, config.GlobalConfig.Hall.Port)
		if err != nil {
			panic(err)
		}
	}()
	//启动微服务
	go func() {
		if err = svc.Run(); err != nil {
			panic(err)
		}
	}()
	////测试用
	//tcp.Start()
}

func Close() {
	httpServer.Close()
}
